{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Falling Dominoes\n",
    "\n",
    "[The original Question](https://mp.weixin.qq.com/s/3phUTGkCkEfT84EHKoa4Xw)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question\n",
    "\n",
    "Given a string with the initial conditions of dominoes, where:\n",
    "\n",
    "- `.` represents that the domino is stading still. \n",
    "- `L` represents that the domino is falling to the left side. \n",
    "- `R` represents that the domino is falling to the right side. \n",
    "\n",
    "Figure out the final position of the dominoes. If there are dominoes that get pushed on both ends, the force cancels out and that domino remains upright. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example\n",
    "\n",
    "```{text}\n",
    "Input: ..R...L..R.\n",
    "Output: ..RR.LL..RR\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "..RR.LL..RR\n"
     ]
    }
   ],
   "source": [
    "class Solution():\n",
    "    def pushDominoes(self, dominoes: str):\n",
    "        # Fill this in. \n",
    "        while True:\n",
    "            temp = list('.' + dominoes + '.')\n",
    "            record = dominoes\n",
    "            for k in range(1, len(temp) - 1):\n",
    "                if (temp[k - 1] == \"R\") and (temp[k + 1] != 'L') and (temp[k] == '.'):\n",
    "                    dominoes = dominoes[:k-1] + 'R' + dominoes[k:]\n",
    "                    pass\n",
    "                elif (temp[k - 1] != 'R') and (temp[k + 1] == 'L') and (temp[k] == '.'):\n",
    "                    dominoes = dominoes[:k-1] + 'L' + dominoes[k:]\n",
    "                    pass\n",
    "                pass\n",
    "            if record == dominoes:\n",
    "                return ''.join(record)\n",
    "            pass\n",
    "        pass\n",
    "    \n",
    "    pass\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    print(Solution().pushDominoes('..R...L..R.'))\n",
    "    pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
